package com.cssw.fyzb.wap.service;

import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.wap.model.vo.GiftLogVo;
import com.cssw.fyzb.wap.model.vo.GiftStatisticsVo;
import com.cssw.fyzb.wap.model.vo.GiftVo;
import com.cssw.fyzb.wap.model.vo.PublicUserInfoVo;
import com.ydn.appserver.MinaAppClient;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wondream
 */
@Service
public class GiftService extends BaseService {

    private static final Logger logger = LoggerFactory.getLogger(UserService.class);

    @Autowired
    private MinaAppClient busiClient;

    /**
     * 获取礼物列表
     *
     * @return
     */
    public AjaxPage listGift() {
        Request request = new Request("ListGift");
        return convertPage(busiClient.send(request), GiftVo.class);
    }

    /**
     * 赠送礼物
     *
     * @param fromUserId
     * @param toUserId
     * @param liveId
     * @param giftId
     * @return
     */
    public AjaxData sendGift(Long fromUserId, Long toUserId, Long liveId, Long giftId) {
        Request request = new Request("SendGift");
        request.setParameter("fromUserId", fromUserId);
        request.setParameter("toUserId", toUserId);
        request.setParameter("liveId", liveId);
        request.setParameter("giftId", giftId);
        return convertData(busiClient.send(request));
    }

    /**
     * 用户礼物日志
     *
     * @return
     */
    public AjaxPage listGiftLog(Long userId, int pageNumber, int pageSize) {
        Request request = new Request("ListGiftLog");
        request.setParameter("userId", userId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), GiftLogVo.class);
    }

    /**
     * 主播收到礼物列表
     *
     * @return
     */
    public AjaxPage listReceivedGift(Long userId, int pageNumber, int pageSize) {
        Request request = new Request("ListReceivedGift");
        request.setParameter("userId", userId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), GiftVo.class);
    }

    /**
     * 用户赠送礼物列表
     *
     * @return
     */
    public AjaxPage listSendGift(Long userId, int pageNumber, int pageSize) {
        Request request = new Request("ListSendGift");
        request.setParameter("userId", userId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), GiftVo.class);
    }

    /**
     * 主播收到礼物统计(根据礼物id)
     *
     * @return
     */
    public AjaxPage receivedGiftStatistics(Long userId, int pageNumber, int pageSize) {
        Request request = new Request("ReceivedGiftStatistics");
        request.setParameter("userId", userId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        Response response = busiClient.send(request);
        List<GiftStatisticsVo>data = response.getList("list", GiftStatisticsVo.class);
        return AjaxPage.success(data, response.getInteger("total"), response.getInteger("count"));
    }

}
